//
//  HZLandscapeSummaryView.m
//  Stock_Health
//
//  Created by MayerF on 2017/8/2.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZLandscapeSummaryView.h"

@interface HZLandscapeSummaryView()
@property (nonatomic, strong)UILabel *pName;
@property (nonatomic, strong)UILabel *pCode;
@property (nonatomic, strong)UILabel *pCurrentPrice;
@property (nonatomic, strong)UILabel *pZhangDie;
@property (nonatomic, strong)UILabel *pZhangFu;
@property (nonatomic, strong)UILabel *pMaxPrice;
@property (nonatomic, strong)UILabel *pMaxPriceContent;
@property (nonatomic, strong)UILabel *pMinPrice;
@property (nonatomic, strong)UILabel *pMinPriceContent;
@property (nonatomic, strong)UILabel *pOpenPrice;
@property (nonatomic, strong)UILabel *pOpenPriceContent;
@property (nonatomic, strong)UILabel *pLastPrice;
@property (nonatomic, strong)UILabel *pLastPriceContent;
@property (nonatomic, strong)UILabel *pHuanShouLv;
@property (nonatomic, strong)UILabel *pHuaShouLvContent;
@property (nonatomic, strong)UILabel *pLiangBi;
@property (nonatomic, strong)UILabel *pLiangBiContent;

@property (nonatomic, strong)UIButton *pOffBtn;
@property (nonatomic, strong)HZOwnedStockModel *pOwnModel;
@end

@implementation HZLandscapeSummaryView

#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = [HZCommonTool getThemeColor];
    }
    return self;
}
- (void)p_commonInit
{
    _pName = [UILabel new];
    _pCode = [UILabel new];
    _pCurrentPrice = [UILabel new];
    _pZhangDie = [UILabel new];
    _pZhangFu = [UILabel new];
    _pMaxPrice = [UILabel new];
    _pMaxPriceContent = [UILabel new];
    _pMinPrice = [UILabel new];
    _pMinPriceContent = [UILabel new];
    _pOpenPrice = [UILabel new];
    _pOpenPriceContent = [UILabel new];
    _pLastPrice = [UILabel new];
    _pLastPriceContent = [UILabel new];
    _pHuanShouLv = [UILabel new];
    _pHuaShouLvContent = [UILabel new];
    _pLiangBi = [UILabel new];
    _pLiangBiContent = [UILabel new];
    _pOffBtn = [UIButton new];
    
    _pZhangDie.textAlignment = _pCurrentPrice.textAlignment = NSTextAlignmentCenter;
    _pZhangFu.textAlignment = NSTextAlignmentCenter;
    _pMaxPriceContent.font = _pOpenPriceContent.font = _pMinPriceContent.font = _pLastPriceContent.font = _pLiangBiContent.font = _pHuaShouLvContent.font = [UIFont systemFontOfSize:15];
    _pZhangDie.font = _pZhangFu.font = [UIFont systemFontOfSize:15];
    _pMaxPrice.font = _pMinPrice.font = _pOpenPrice.font = _pLastPrice.font = _pHuanShouLv.font = _pLiangBi.font = [UIFont systemFontOfSize:15];
    _pName.font = _pCode.font = [UIFont systemFontOfSize:15];
    
    _pMaxPrice.textAlignment = _pOpenPrice.textAlignment = _pHuanShouLv.textAlignment = _pMinPrice.textAlignment = _pLastPrice.textAlignment = _pLiangBi.textAlignment = NSTextAlignmentCenter;
    _pMaxPriceContent.textAlignment = _pOpenPriceContent.textAlignment = _pHuaShouLvContent.textAlignment = _pMinPriceContent.textAlignment = _pLastPriceContent.textAlignment =
    _pLiangBiContent.textAlignment = NSTextAlignmentCenter;
    
    _pMaxPriceContent.adjustsFontSizeToFitWidth = YES;
    _pOpenPriceContent.adjustsFontSizeToFitWidth = YES;
    _pMinPriceContent.adjustsFontSizeToFitWidth = YES;
    _pLastPriceContent.adjustsFontSizeToFitWidth = YES;
    _pHuaShouLvContent.adjustsFontSizeToFitWidth = YES;
    _pLiangBiContent.adjustsFontSizeToFitWidth = YES;
    _pZhangFu.adjustsFontSizeToFitWidth = YES;
    _pZhangDie.adjustsFontSizeToFitWidth = YES;
    _pCurrentPrice.adjustsFontSizeToFitWidth = YES;
    _pName.adjustsFontSizeToFitWidth = YES;
    
    [self addSubview:_pName];
    [self addSubview:_pCode];
    [self addSubview:_pCurrentPrice];
    [self addSubview:_pZhangDie];
    [self addSubview:_pZhangFu];
    [self addSubview:_pMaxPrice];
    [self addSubview:_pMaxPriceContent];
    [self addSubview:_pMinPrice];
    [self addSubview:_pMinPriceContent];
    [self addSubview:_pOpenPrice];
    [self addSubview:_pOpenPriceContent];
    [self addSubview:_pLastPrice];
    [self addSubview:_pLastPriceContent];
    [self addSubview:_pHuanShouLv];
    [self addSubview:_pHuaShouLvContent];
    [self addSubview:_pLiangBi];
    [self addSubview:_pLiangBiContent];
    [self addSubview:_pOffBtn];
    
    _pName.textColor = _pCode.textColor = kMYHexToRGB(0x888888, 1);
    _pMaxPrice.textColor = _pMinPrice.textColor = _pOpenPrice.textColor =
    _pLastPrice.textColor = _pLiangBi.textColor = _pHuanShouLv.textColor = kMYHexToRGB(0x888888, 1);
    
    [_pOffBtn setImage:[UIImage imageNamed:@"off"] forState:UIControlStateNormal];
    [_pOffBtn addTarget:self action:@selector(offBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self p_updateConstraintsWithCodeInfo:nil];
    [self p_updateDefaultInfoWithCodeInfo:nil];
}
#pragma mark -
#pragma mark public
- (void)updateOwnModel:(HZOwnedStockModel *)ownModel
{
    _pOwnModel = ownModel;
}
- (void)updateNewData:(HZMinPriceModel *)data fromType:(KFromType)fromType
{
    if (fromType == KFromMinType) {
        _pHuanShouLv.hidden = _pHuaShouLvContent.hidden = _pLiangBi.hidden = _pLiangBiContent.hidden = YES;
//        _pHuanShouLv.text = @"换手";
//        _pLiangBi.text = @"量比";
//        _pHuaShouLvContent.text = data.model_huanShouLv;
//        _pLiangBiContent.text = data.model_liangBi;
    }else {
        _pHuanShouLv.hidden = _pHuaShouLvContent.hidden = _pLiangBi.hidden = _pLiangBiContent.hidden = NO;
        _pHuanShouLv.text = @"成交量";
        _pLiangBi.text = @"成交额";
        _pHuaShouLvContent.text = data.model_chengJiaoLiang;
        _pLiangBiContent.text = data.model_chengJiaoE;
    }
    _pName.text = _pOwnModel.model_Name;
    _pCode.text = _pOwnModel.model_Code;
    _pCurrentPrice.text = data.model_currentPrice;
    _pZhangDie.text = data.model_zhangDie;
    _pZhangFu.text = data.model_zhangFu;
    _pMaxPriceContent.text = data.model_maxPrice;
    _pMinPriceContent.text = data.model_minPrice;
    _pOpenPriceContent.text = data.model_openPrice;
    _pLastPriceContent.text = data.model_prePrice;
    CGFloat fPrePrice = [data.model_prePrice floatValue];
    _pCurrentPrice.textColor = _pZhangDie.textColor = _pZhangFu.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_currentPrice floatValue] value2:fPrePrice];
    _pMaxPriceContent.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_maxPrice floatValue] value2:fPrePrice];
    _pMinPriceContent.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_minPrice floatValue] value2:fPrePrice];
    
    [self updateThemeColor];
}
#pragma mark -
#pragma mark private
- (void)p_updateConstraintsWithCodeInfo:(HZOwnedStockModel *)codeInfo
{
    [_pName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(10);
        make.bottom.mas_equalTo(_pCode.mas_top);
        make.width.mas_equalTo(65);
    }];
    [_pCurrentPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pName);
        make.left.mas_equalTo(_pName.mas_right);
        make.bottom.mas_equalTo(self);
    }];
    [_pZhangDie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pName);
        make.left.mas_equalTo(_pCurrentPrice.mas_right);
        make.bottom.mas_equalTo(_pName);
    }];
    
    [_pMaxPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pZhangDie);
        make.left.mas_equalTo(_pZhangDie.mas_right).offset(5);
        make.bottom.mas_equalTo(_pZhangDie);
        make.width.mas_equalTo(50);
    }];
    [_pMaxPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pMaxPrice);
        make.left.mas_equalTo(_pMaxPrice.mas_right);
        make.height.mas_equalTo(_pMaxPrice);
    }];
    [_pOpenPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pMaxPriceContent);
        make.left.mas_equalTo(_pMaxPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pMaxPriceContent);
    }];
    [_pOpenPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pOpenPrice.mas_right);
        make.bottom.mas_equalTo(_pOpenPrice);
    }];
    [_pHuanShouLv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPriceContent);
        make.left.mas_equalTo(_pOpenPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pOpenPriceContent);
        make.width.mas_equalTo(@[_pOpenPrice,_pMaxPrice]);
    }];
    [_pHuaShouLvContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pHuanShouLv.mas_right);
        make.bottom.mas_equalTo(_pOpenPrice);
        make.right.mas_equalTo(_pOffBtn.mas_left);
        make.width.mas_equalTo(@[_pOpenPriceContent, _pMaxPriceContent,_pCurrentPrice, _pZhangDie]);
    }];
    
    [_pCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_pName);
        make.bottom.mas_equalTo(self);
        make.width.mas_equalTo(_pName);
        make.height.mas_equalTo(_pName);
    }];
    [_pZhangFu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pCode);
        make.left.mas_equalTo(_pCurrentPrice.mas_right);
        make.bottom.mas_equalTo(_pCode);
    }];
    [_pMinPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pZhangFu);
        make.left.mas_equalTo(_pZhangFu.mas_right).offset(5);
        make.bottom.mas_equalTo(_pZhangFu);
        make.width.mas_equalTo(_pMaxPrice);
    }];
    [_pMinPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pMinPrice);
        make.left.mas_equalTo(_pMinPrice.mas_right);
        make.height.mas_equalTo(_pMinPrice);
    }];
    [_pLastPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pMinPriceContent);
        make.left.mas_equalTo(_pMinPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pMinPriceContent);
    }];
    [_pLastPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pLastPrice.mas_right);
        make.bottom.mas_equalTo(_pLastPrice);
    }];
    [_pLiangBi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPriceContent);
        make.left.mas_equalTo(_pLastPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pLastPriceContent);
        make.width.mas_equalTo(@[_pLastPrice,_pMinPrice]);
    }];
    [_pLiangBiContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLiangBi);
        make.left.mas_equalTo(_pLiangBi.mas_right);
        make.bottom.mas_equalTo(_pLiangBi);
        make.right.mas_equalTo(_pOffBtn.mas_left);
        make.width.mas_equalTo(@[_pOpenPriceContent, _pMinPriceContent, _pZhangFu]);
    }];
    
    [_pOffBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(self);
        make.width.mas_equalTo(50);
    }];
    
}

- (void)p_updateDefaultInfoWithCodeInfo:(HZOwnedStockModel *)codeInfo
{
    if (codeInfo.nModel_Style == 1) {
        _pMaxPriceContent.text = _pMinPriceContent.text = _pOpenPriceContent.text = _pLastPriceContent.text = kDefaultContent;
        _pMaxPrice.text = kHZMaxPrice;
        _pMinPrice.text = kHZMinPrice;
        _pOpenPrice.text = kHZOpenPrice;
        _pLastPrice.text = kHZE;
    }else {
        _pZhangFu.text = _pZhangDie.text = kDefaultContent;
        _pMaxPriceContent.text = _pMinPriceContent.text = _pOpenPriceContent.text = _pLastPriceContent.text = _pHuaShouLvContent.text = _pLiangBiContent.text = kDefaultContent;
        _pMaxPrice.text = @"最高";
        _pMinPrice.text = @"最低";
        _pOpenPrice.text = @"开盘";
        _pLastPrice.text = @"昨收";
        _pHuanShouLv.text = @"量";
        _pLiangBi.text = @"额";
    }
}

- (void)offBtnOnClick
{
    [self.parent upToParentWithObjc:self withType:kHZ_cancelLandscapeScreen_Action withParamter:nil];
}

- (void)updateThemeColor
{
    _pLastPriceContent.textColor = _pOpenPriceContent.textColor =
    _pLiangBiContent.textColor = _pHuaShouLvContent.textColor = [HZCommonTool getThemeZhangDieColor];
}

@end
